import { Prop, Provide, Emit, Model } from 'vue-property-decorator';
import { Subject, Subscription } from 'rxjs';
import { UIActionTool,Util,ViewTool } from '@/utils';
import { Watch, GridControlBase } from '@/studio-core';
import EMEQCheckService from '@/service/emeqcheck/emeqcheck-service';
import Main2Service from './main2-grid-service';
import EMEQCheckUIService from '@/uiservice/emeqcheck/emeqcheck-ui-service';
import { FormItemModel } from '@/model/form-detail';


/**
 * grid部件基类
 *
 * @export
 * @class GridControlBase
 * @extends {Main2GridBase}
 */
export class Main2GridBase extends GridControlBase {

    /**
     * 获取部件类型
     *
     * @protected
     * @type {string}
     * @memberof Main2GridBase
     */
    protected controlType: string = 'GRID';

    /**
     * 建构部件服务对象
     *
     * @type {Main2Service}
     * @memberof Main2GridBase
     */
    public service: Main2Service = new Main2Service({ $store: this.$store });

    /**
     * 实体服务对象
     *
     * @type {EMEQCheckService}
     * @memberof Main2GridBase
     */
    public appEntityService: EMEQCheckService = new EMEQCheckService({ $store: this.$store });

    /**
     * 应用实体名称
     *
     * @protected
     * @type {string}
     * @memberof Main2GridBase
     */
    protected appDeName: string = 'emeqcheck';

    /**
     * 应用实体中文名称
     *
     * @protected
     * @type {string}
     * @memberof Main2GridBase
     */
    protected appDeLogicName: string = '维修记录';

    /**
     * 界面UI服务对象
     *
     * @type {EMEQCheckUIService}
     * @memberof Main2Base
     */  
    public appUIService:EMEQCheckUIService = new EMEQCheckUIService(this.$store);


    /**
     * 界面行为模型
     *
     * @type {*}
     * @memberof Main2Base
     */  
    public ActionModel: any = {
    };

    /**
     * 主信息表格列
     *
     * @type {string}
     * @memberof Main2Base
     */  
    public majorInfoColName:string = "";


    /**
     * 本地缓存标识
     *
     * @protected
     * @type {string}
     * @memberof Main2Base
     */
    protected localStorageTag: string = 'emeqcheck_main2_grid';

    /**
     * 所有列成员
     *
     * @type {any[]}
     * @memberof Main2GridBase
     */
    public allColumns: any[] = [
        {
            name: 'equipname',
            label: '设备',
            langtag: 'entities.emeqcheck.main2_grid.columns.equipname',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'objname',
            label: '位置',
            langtag: 'entities.emeqcheck.main2_grid.columns.objname',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'woname',
            label: '工单',
            langtag: 'entities.emeqcheck.main2_grid.columns.woname',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'activedate',
            label: '检修日期',
            langtag: 'entities.emeqcheck.main2_grid.columns.activedate',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'activedesc',
            label: '检修记录',
            langtag: 'entities.emeqcheck.main2_grid.columns.activedesc',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'regionbegindate',
            label: '起始时间',
            langtag: 'entities.emeqcheck.main2_grid.columns.regionbegindate',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'regionenddate',
            label: '结束时间',
            langtag: 'entities.emeqcheck.main2_grid.columns.regionenddate',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'activeadesc',
            label: '检修结果',
            langtag: 'entities.emeqcheck.main2_grid.columns.activeadesc',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'rempname',
            label: '责任人',
            langtag: 'entities.emeqcheck.main2_grid.columns.rempname',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'rdeptname',
            label: '责任部门',
            langtag: 'entities.emeqcheck.main2_grid.columns.rdeptname',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'rteamname',
            label: '责任班组',
            langtag: 'entities.emeqcheck.main2_grid.columns.rteamname',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'rservicename',
            label: '服务商',
            langtag: 'entities.emeqcheck.main2_grid.columns.rservicename',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'rfodename',
            label: '现象',
            langtag: 'entities.emeqcheck.main2_grid.columns.rfodename',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'rfomoname',
            label: '模式',
            langtag: 'entities.emeqcheck.main2_grid.columns.rfomoname',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'rfocaname',
            label: '原因',
            langtag: 'entities.emeqcheck.main2_grid.columns.rfocaname',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'rfoacname',
            label: '方案',
            langtag: 'entities.emeqcheck.main2_grid.columns.rfoacname',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'eqstoplength',
            label: '停运时间(分)',
            langtag: 'entities.emeqcheck.main2_grid.columns.eqstoplength',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'activelengths',
            label: '持续时间(H)',
            langtag: 'entities.emeqcheck.main2_grid.columns.activelengths',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'prefee',
            label: '预算(￥)',
            langtag: 'entities.emeqcheck.main2_grid.columns.prefee',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'mfee',
            label: '材料费(￥)',
            langtag: 'entities.emeqcheck.main2_grid.columns.mfee',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'pfee',
            label: '人工费(￥)',
            langtag: 'entities.emeqcheck.main2_grid.columns.pfee',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
        {
            name: 'sfee',
            label: '服务费(￥)',
            langtag: 'entities.emeqcheck.main2_grid.columns.sfee',
            show: true,
            unit: 'PX',
            isEnableRowEdit: false,
            enableCond: 3 ,
        },
    ]

    /**
     * 获取表格行模型
     *
     * @type {*}
     * @memberof Main2GridBase
     */
    public getGridRowModel(){
        return {
          srfkey: new FormItemModel(),
        }
    }

    /**
     * 属性值规则
     *
     * @type {*}
     * @memberof Main2GridBase
     */
    public rules: any = {
        srfkey: [
            { required: false, validator: (rule:any, value:any, callback:any) => { return (rule.required && (value === null || value === undefined || value === "")) ? false : true;}, message: '检修记录标识 值不能为空', trigger: 'change' },
            { required: false, validator: (rule:any, value:any, callback:any) => { return (rule.required && (value === null || value === undefined || value === "")) ? false : true;}, message: '检修记录标识 值不能为空', trigger: 'blur' },
        ],
    }

    /**
     * 属性值规则
     *
     * @type {*}
     * @memberof Main2Base
     */
    public deRules:any = {
    };

    /**
     * 获取对应列class
     *
     * @type {*}
     * @memberof Main2Base
     */
    public hasRowEdit: any = {
        'equipname':false,
        'objname':false,
        'woname':false,
        'activedate':false,
        'activedesc':false,
        'regionbegindate':false,
        'regionenddate':false,
        'activeadesc':false,
        'rempname':false,
        'rdeptname':false,
        'rteamname':false,
        'rservicename':false,
        'rfodename':false,
        'rfomoname':false,
        'rfocaname':false,
        'rfoacname':false,
        'eqstoplength':false,
        'activelengths':false,
        'prefee':false,
        'mfee':false,
        'pfee':false,
        'sfee':false,
    };

    /**
     * 获取对应列class
     *
     * @param {*} $args row 行数据，column 列数据，rowIndex 行索引，列索引
     * @returns {void}
     * @memberof Main2Base
     */
    public getCellClassName(args: {row: any, column: any, rowIndex: number, columnIndex: number}): any {
        return ( this.hasRowEdit[args.column.property] && this.actualIsOpenEdit ) ? "edit-cell" : "info-cell";
    }


    /**
     * 导出数据格式化
     *
     * @param {*} filterVal
     * @param {*} jsonData
     * @param {any[]} [codelistColumns=[]]
     * @returns {Promise<any>}
     * @memberof Main2GridBase
     */
    public async formatExcelData(filterVal: any, jsonData: any, codelistColumns?: any[]): Promise<any> {
        return super.formatExcelData(filterVal, jsonData, [
        ]);
    }


    /**
     * 更新默认值
     * @param {*}  row 行数据
     * @memberof Main2Base
     */
    public updateDefault(row: any){                    
    }

    /**
     * 计算数据对象类型的默认值
     * @param {string}  action 行为
     * @param {string}  param 默认值参数
     * @param {*}  data 当前行数据
     * @memberof Main2Base
     */
    public computeDefaultValueWithParam(action:string,param:string,data:any){
        if(Object.is(action,"UPDATE")){
            const nativeData:any = this.service.getCopynativeData();
            if(nativeData && (nativeData instanceof Array) && nativeData.length >0){
                let targetData:any = nativeData.find((item:any) =>{
                    return item.emeqcheckid === data.srfkey;
                })
                if(targetData){
                    return targetData[param]?targetData[param]:null;
                }else{
                    return null;
                }
            }else{
                return null;
            }
        }else{
           return this.service.getRemoteCopyData()[param]?this.service.getRemoteCopyData()[param]:null;
        }
    }


}